using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace GrpcClient.Assets.CustomModels
{
    public class CustomWindow : CustomWindowBase
    {
        protected event Action? BackToLoginEvent;
        protected event Action? OpenUserCenterEvent;
        protected event Action? OpenSettingEvent;

        public CustomWindow()
        {
            CommandBindings.Add(new CommandBinding(CustomCommands.BackToLoginCommand, OnBackToLogin));
            CommandBindings.Add(new CommandBinding(CustomCommands.OpenUserCenterCommand, OpenUserCenter));
            CommandBindings.Add(new CommandBinding(CustomCommands.OpenSettingCommand, OpenSetting));
            CommandBindings.Add(new CommandBinding(CustomCommands.TopWindowCommand, TopWindow));
            CommandBindings.Add(new CommandBinding(CustomCommands.SetThemeCommand));
        }

        private bool isTop;
        private void TopWindow(object sender, ExecutedRoutedEventArgs e)
        {
            isTop = !isTop;
            this.Topmost = isTop;
        }

        private void OpenSetting(object sender, ExecutedRoutedEventArgs e)
        {
            if (OpenSettingEvent != null)
            {
                OpenSettingEvent.Invoke();
            }
        }

        private void OpenUserCenter(object sender, ExecutedRoutedEventArgs e)
        {
            if (OpenUserCenterEvent != null)
            {
                OpenUserCenterEvent.Invoke();
            }
        }

        private void OnBackToLogin(object sender, ExecutedRoutedEventArgs e)
        {
            if (BackToLoginEvent != null)
            {
                BackToLoginEvent.Invoke();
            }
        }



        public string UserName
        {
            get { return (string)GetValue(UserNameProperty); }
            set { SetValue(UserNameProperty, value); }
        }

        public static readonly DependencyProperty UserNameProperty =
            DependencyProperty.Register("UserName", typeof(string), typeof(CustomWindow));




        public string Url
        {
            get { return (string)GetValue(UrlProperty); }
            set { SetValue(UrlProperty, value); }
        }

        public static readonly DependencyProperty UrlProperty =
            DependencyProperty.Register("Url", typeof(string), typeof(CustomWindow));




        public ContextMenu InitMenu()
        {
            ContextMenu menu = new ContextMenu();

            return menu;
        }
    }
}
